#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstdlib>

#define maxn 40011

using namespace std;


int ntest, n, d[maxn], f[maxn], h[maxn], t[140000], result;

int findPos(int v, int l, int r, int m, int n)
{
	//cout << "Visit " << v << " " << l << " " << r << " " << m << " " << n << endl;
	if (n == 0) return 0;
	if ((m <= l) && (r <= n)) return t[v];

	int p = (l+r)/2;
	if (m <= p)
	{
		if (n <= p) return findPos(2*v, l, p, m, n);

		int a = findPos(2*v, l, p, m, n);
		int b = findPos(2*v+1, p+1, r, m, n);
		if (d[h[a]] > d[h[b]]) return a;
		return b;
	}

	return findPos(2*v+1, p+1, r, m, n);
}

void update(int v, int l, int r, int m)
{
	//cout << "Update " << v << " " << l << " " << r << " " << m << endl;
	if (l == m && m == r) t[v] = m;
	else
	{
		int p = (l+r)/2;
		if (m <= p) update(2*v, l, p, m);
		else update(2*v+1, p+1, r, m);

		t[v] = (d[h[t[2*v]]] > d[h[t[2*v+1]]]) ? t[2*v] : t[2*v+1];
	}
}

int main()
{
	cin >> ntest;
	while (0 < ntest--)
	{
		cin >> n;
		result = -1;
		for (int i = 1; i <= n; i++)
		{
			int x;
			cin >> x;
			f[i] = x;
			h[x] = i;
		}

		h[0] = 0;
		memset(d, 0, sizeof(d));
		memset(t, 0, sizeof(t));

		for (int i = 1; i <= n; i++)
		{
			int k = findPos(1, 1, n, 1, f[i]-1);

			d[i] = d[h[k]]+1;
			update(1, 1, n, f[i]);

			result = max(result, d[i]);
		}

		cout << result << endl;
	}
}
